//
//  SYCollectionTableViewCell.m
//  SanYiTeaching
//
//  Created by 郑浩然 on 2019/4/12.
//  Copyright © 2019年 李文强. All rights reserved.
//

#import "SYCollectionTableViewCell.h"

@interface SYCollectionTableViewCell ()
@property (weak, nonatomic) IBOutlet UIImageView *headerImage;//头
@property (weak, nonatomic) IBOutlet UILabel *titleLab;//标题
@property (weak, nonatomic) IBOutlet UILabel *timerLab;//时间
@property (weak, nonatomic) IBOutlet UILabel *datelAB;//日期
@property (weak, nonatomic) IBOutlet UIImageView *fanHuiImage;//列表

@property (strong, nonatomic) NSIndexPath *indexPath;
@end



@implementation SYCollectionTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];
    [self addGestureRecognizer:longPress];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)functionTableModel:(SYCollectionModel *)model indexPath:(NSIndexPath *)index {
    _indexPath = index;
    _fanHuiImage.hidden = YES;
    
    
    UIImage *placeholderImage = nil;
    if ([model.type isEqualToString:@"1"] || [model.type isEqualToString:@"2"]) {//新建文件 zy_collection_mrtp
        placeholderImage = [UIImage imageNamed:@"zy_collection_xjwjj"];
    } else if ([model.type isEqualToString:@"5"]) {//微课程
        placeholderImage = [UIImage imageNamed:@"zy_view_wdvs"];
    }
    else {//默认课程
        placeholderImage = [UIImage imageNamed:@"zy_collection_mrtp"];
    }
    [self.headerImage sd_setImageWithURL:[NSURL URLWithString:model.fileIcon] placeholderImage:placeholderImage];
    self.titleLab.text = model.titleName;
    self.datelAB.text = model.dateTime;
    if ([model.type isEqualToString:@"1"]) {
        self.timerLab.text = SYStringWithPickFormat(model.timer, @"项");
    } else {
                if ([model.type isEqualToString:@"3"] || [model.type isEqualToString:@"9"]) {
        //            if (model.chec) {
        //                <#statements#>
        //            }
                    self.timerLab.text = model.checkStatusName;
                } else {
                    self.timerLab.text = model.timer;
                }
        
    }
    
}


- (void)setCollectionModel:(SYCollectionModel *)collectionModel {
    
    
    
}
- (void)longPress:(UILongPressGestureRecognizer *)longPress {
    
    if (longPress.state == UIGestureRecognizerStateBegan) {
        [self becomeFirstResponder];
        UIMenuController *menu = [UIMenuController sharedMenuController];
        [menu setTargetRect:CGRectMake(300, 10, 180, 20) inView:self];
        // 定义两个菜单a和b
        UIMenuItem *a = [[UIMenuItem alloc] initWithTitle:@"重命名"
                                                   action:@selector(aAction)];
        UIMenuItem *b = [[UIMenuItem alloc] initWithTitle:@"移动"
                                                   action:@selector(bAction)];
        UIMenuItem *c = [[UIMenuItem alloc] initWithTitle:@"删除"
                                                   action:@selector(cAction)];
        
        //我的作品，我的微课 可以 移动，删除,重命名   微课子课只能重命名，移动  我的收藏 只能移出
        if ( self.type == SYCollectionViewTypeMinWenJian) {
            menu.menuItems = @[a,b,c];
        } else if (self.type == SYCollectionViewTypeWeiKeTiaoZhuan) {
            menu.menuItems = @[a,c];
        } else if (self.type == SYCollectionViewTypeShouCang) {
            menu.menuItems = @[c];
        } else if (self.type == SYCollectionViewTypeWeiKe) {
            menu.menuItems = @[a];
        }
        else {
            menu.menuItems = @[];
        }
        
        menu.menuVisible = YES;
        
    }
}
- (BOOL)canBecomeFirstResponder
{
    if (self.type == SYCollectionViewTypeWeiKe || self.type == SYCollectionViewTypeMinWenJian||self.type == SYCollectionViewTypeWeiKeTiaoZhuan || self.type == SYCollectionViewTypeShouCang) {
        return YES;
    } else {
        return NO;
    }
    
}
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
    // 显示一个系统的paste以及自定义的a，b菜单
    if (
        action == @selector(aAction) ||
        action == @selector(bAction)||
        action == @selector(cAction))
    {
        return YES;
    }
    else{
        return NO;
    }
}
//重命名2
- (void)aAction {
    [self backOffAgentIndex:2];
}
//移动3
- (void)bAction {
    [self backOffAgentIndex:3];
}
//删除1
- (void)cAction {
    [self backOffAgentIndex:1];
}
//代理的会掉
- (void)backOffAgentIndex:(NSInteger)index {
    if ([self.delegate respondsToSelector:@selector(selectTableLogPressType:indexPath:)]) {
        [self.delegate selectTableLogPressType:index indexPath:self.indexPath];
    }
    
    
}
@end




















